import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import remove from '@dfeidao/atom-web/local/remove';

import get from '@dfeidao/atom-web/local/get';
import set from '@dfeidao/atom-web/local/set';

// import javadsd from '@dfeidao/atom-web/msg/javadsd';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import error from '@dfeidao/atom-web/msgbox/error';
import success from '@dfeidao/atom-web/msgbox/success';
import a002 from './a002';
import { spaceid } from './config';


export default async function a003(fd: IFeidaoAiBrowserComponent) {
	// 保存


	const tenantid = get(fd, 'tenantid');

	const tenant_name = fd.data.node.querySelector<HTMLInputElement>('[data-feidao-name="name"]').value;
	if (!tenant_name) {
		error('租户名称不能为空!');
		return;
	}
	const link_man = fd.data.node.querySelector<HTMLInputElement>('[data-feidao-name="user"]').value;
	const phone = fd.data.node.querySelector<HTMLInputElement>('[data-feidao-name="phone"]').value;
	const email = fd.data.node.querySelector<HTMLInputElement>('[data-feidao-name="email"]').value;


	// const productid = get(fd, 'productid');
	// console.log(productid, '----',spaceid);
	const usercode = get(fd, 'usercode');
	const user_name = get(fd, 'user_name');

	if (get(fd, 'prevent')) {
		return;
	}
	set(fd, 'prevent', 1);
	const res = await nodejs('tenant-inf/zj-000003/s002', { productid: spaceid, tenantid, tenant_name, link_man, phone, email, usercode, user_name });
	if (res === 'success') {
		success('修改成功!');
		remove(fd, 'prevent');
		await a002(fd);
	} else if (res === 'fail') {
		error('修改失败!');
		return;
	} else {
		error('租户名称重复!');
		return;
	}

}
